<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">修改密码</block>
		</cu-custom>
		<view class="form">
			<view class="inputbox">
				<text class="lg cuIcon-lock"></text>
				<input class="f_input" type="password" v-model="loginFrom.password" placeholder="原密码" />
			</view>
			<view class="inputbox">
				<text class="lg  cuIcon-lock"></text>
				<input class="f_input" type="password" placeholder="新密码" v-model="loginFrom.newPassword" />
			</view>
			<view class="inputbox"><text class="lg  cuIcon-lock"></text>
				<input class="f_input" type="password" placeholder="确认密码" v-model="loginFrom.confirmPwd" /></view>
			<view class="btnbox" @tap="updatePwd">确定</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loginFrom: {
					newPassword: "",
					password: "",
					confirmPwd: ""
				}
			}
		},
		methods: {
			updatePwd: function() {

				if (this.loginFrom.password == '') {
					uni.showToast({
						icon: 'none',
						title: '原密码不能为空'
					});
					return;
				}
				if (this.loginFrom.newPassword == '') {
					uni.showToast({
						icon: 'none',
						title: '新密码不能为空'
					});
					return;
				}
				if (this.loginFrom.newPassword != this.loginFrom.confirmPwd) {
					uni.showToast({
						icon: 'none',
						title: '新密码和确认密码不一致'
					});
					return;
				}
				uni.request({
					url: this.$http+'/sys/sysUser/password',
					data: this.loginFrom,
					header:{
						token:uni.getStorageSync("token")
					},
					method:'POST',
					success: (res) => {
						if (res.statusCode == 200 && res.data.code==0) {
							uni.showToast({
								icon: 'none',
								title: '密码修改成功！'
							});
							uni.navigateBack();
						}else{
							uni.showToast({
								icon: 'none',
								title: '密码修改失败，请重试！'
							});
						}
					},
					fail:function(){
						uni.showToast({
							icon: 'none',
							title: '服务器请求超时！'
						});
					}
				})
			}
		}
	}
</script>

<style>
	.form {
		height: 50vh;
		width: 100%;
		display: flex;
		flex-direction: column;
		justify-content: start;
		align-items: center;
	}

	.inputbox {
		width: 679.16rpx;
		height: 80rpx;
		border: 1px #D0D0D0 solid;
		border-radius: 10rpx;
		margin-top: 20rpx;
		font-size: 41.66rpx;
		color: #116AB7;
		line-height: 80rpx;
		padding-left: 20.41rpx;
		display: flex;
	}

	.f_input {
		width: 416.66rpx;
		height: 40rpx;
		margin-left: 20.83rpx;
		margin-top: 20rpx;
	}

	.btnbox {
		width: 679.16rpx;
		height: 80rpx;
		border-radius: 10rpx;
		margin-top: 30rpx;
		background-color: #116AB7;
		font-size: 37.5rpx;
		color: #fff;
		line-height: 80rpx;
		text-align: center;
	}
</style>
